using System;
using UnityEngine;

public class GameModeManager : MonoBehaviour
{
	[Serializable]
	public class EditorReferences
	{
		public GameModeParameters defaultMode;

		public GameModeParameters[] gameModes;
	}

	private static GameModeManager _instance;

	[SerializeField]
	public EditorReferences references = new EditorReferences();

	private GameModeParameters _currentMode;

	public static GameModeManager Instance
	{
		get
		{
			if (_instance == null)
			{
				_instance = UnityEngine.Object.FindObjectOfType<GameModeManager>();
				UnityEngine.Object.DontDestroyOnLoad(_instance.gameObject);
			}
			return _instance;
		}
	}

	public GameModeParameters CurrentMode
	{
		get
		{
			return _currentMode;
		}
		set
		{
			_currentMode = value;
		}
	}

	public bool IsModeTimer => (bool)_currentMode && _currentMode.id == "Timer";

	public bool IsModeSpeedRun => (bool)_currentMode && _currentMode.id == "BattleRoyale";

	public bool IsModeBattleRoyale => (bool)_currentMode && _currentMode.id == "SpeedRun";

	private void Awake()
	{
		if (_instance == null)
		{
			_instance = this;
			UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
		}
		else if (_instance != this)
		{
			UnityEngine.Object.Destroy(base.gameObject);
		}
	}

	public void SetLastMode(string id)
	{
		_currentMode = GetModeWithId(id);
	}

	private GameModeParameters GetModeWithId(string id)
	{
		GameModeParameters[] gameModes = references.gameModes;
		foreach (GameModeParameters gameModeParameters in gameModes)
		{
			if (gameModeParameters.id == id)
			{
				return gameModeParameters;
			}
		}
		return references.defaultMode;
	}
}
